package kuzmenkov.oip.controller;

import kuzmenkov.oip.service.ContactService;
import kuzmenkov.oip.service.impl.ContactItem;
import org.springframework.web.jsf.FacesContextUtils;

import javax.faces.context.FacesContext;
import java.util.List;
import java.util.logging.Logger;

/**
 * This is a backing bean of a contact page
 * User: Michael Kuzmenkov
 * Date: 27.03.2009
 * Time: 11:47:44
 */
public class ContactController extends ErrorSupport {
    private static final Logger log = Logger.getLogger("global");

    private ContactService service;

    public ContactService getService() {
        return service;
    }

    public ContactController() {
        try {
            service = (ContactService) FacesContextUtils.
                    getWebApplicationContext(FacesContext.getCurrentInstance()).
                    getBean("contactService");
        } catch (Exception e) {
            addError(e);
        }
    }


    public List<ContactItem> getContacts() {
        List<ContactItem> cs = null;
        try {
            cs = service.getContactItems();
        } catch (Exception e) {
            addError(e);
        }
        return cs;
    }

    public String getProducerName() {
        String name = null;
        try {
            name = service.getProducerName();
        } catch (Exception e) {
            addError(e);
        }
        return name;
    }

    public String getLogoImage() {
        String path = null;
        try {
            path = service.getLogoImage();
        } catch (Exception e) {
            addError(e);
        }
        if (path != null) {

            path = "../" + path;
        }
        log.info("The path to logo: " + path);
        return path;
    }

    public int getLogoWidth() {
        int width = 100;
        try {
            width = service.getLogoWidth();
        } catch (Exception e) {
            addError(e);
        }
        return width;
    }

    public int getLogoHeight() {
        int height = 100;
        try {
            height = service.getLogoHeight();
        } catch (Exception e) {
            addError(e);
        }
        return height;
    }
}

